<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<jsp:include page="/WEB-INF/common/urls.jsp"/>
<html lang="zh-CN">
<head>
    <title>${applicationScope.PROJECT_NAME}-用户图书管理</title>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no, shrink-to-fit=no">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/lib/bootstrap-5.3.0-alpha1-dist/css/bootstrap.min.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/css/global.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/css/main.css">
    <script src="${pageContext.request.contextPath}/lib/bootstrap-5.3.0-alpha1-dist/js/bootstrap.bundle.min.js"></script>
    <script src="${pageContext.request.contextPath}/lib/jquery-3.5.1.min.js"></script>
    <style>

    </style>
    <script>
        $(() => {
            $('.page-link').each((index, element) => {
                const $link = $(element)
                const originalHref = $link.attr('href')

                $link.on('click', e => {
                    e.preventDefault()

                    // 解析原始href中的URL和参数
                    const url = new URL(originalHref, window.location.origin)
                    const params = url.searchParams

                    // 获取当前页面的参数
                    const currentParams = new URLSearchParams(window.location.search)

                    // 将当前页面的参数添加到新URL中，但不覆盖链接中已有的参数
                    currentParams.forEach((value, key) => {
                        if (!params.has(key)) {
                            params.append(key, value)
                        }
                    })

                    // 设置新的搜索参数
                    url.search = params.toString()

                    // 跳转到新的URL
                    window.location.href = url.toString()
                })
            })
        })
    </script>
</head>

<body>
<header class="navbar navbar-expand-lg navbar-dark bg-body-secondary">
    <div class="container-fluid">
        <a class="navbar-brand navbar-logo" href="#">
            <svg class="logo" width="40" height="40" viewBox="0 0 40 40" xmlns="http://www.w3.org/2000/svg">
                <path d="M10,5 L30,5 L35,10 L35,35 L5,35 L5,10 L10,5" fill="none" stroke="#1E88E5" stroke-width="2"/>
                <path d="M10,5 L10,10 L5,10" fill="none" stroke="#1E88E5" stroke-width="2"/>
                <path d="M12,15 L28,15 M12,20 L28,20 M12,25 L28,25 M12,30 L28,30" stroke="#1E88E5" stroke-width="1.5"/>
            </svg>
            <span>${applicationScope.PROJECT_NAME}</span>
        </a>
    </div>
</header>

<main class="main">
    <!-- 侧边栏 -->
    <div class="sidebar bg-light pt-3">
        <ul class="nav flex-column">
            <li class="nav-item">
                <a class="nav-link" href="${userUrl}/view/notice">公告通知</a>
            </li>
            <li class="nav-item">
                <a class="nav-link" href="${userUrl}/view/book">图书查看</a>
            </li>
            <li class="nav-item">
                <a class="nav-link" href="${userUrl}/view/borrow_record">借阅记录</a>
            </li>
            <li class="nav-item">
                <a class="nav-link" href="${publicUrl}/logout">退出登录</a>
            </li>
        </ul>
    </div>

    <!-- 主体部分 -->
    <div class="main-content">
        <div class="list-group">
            <c:forEach var="item" items="${list}">
                <a href="#" class="list-group-item list-group-item-action">
                    <div class="d-flex w-100 justify-content-between">
                        <h5 class="mb-1">${item.title}</h5>
                        <small class="text-muted">${item.publishDateString}</small>
                    </div>
                    <p class="mb-1">${item.content}</p>
                </a>
            </c:forEach>
        </div>
    </div>
</main>
<jsp:include page="/footer" />
</body>
</html>